// odoo.define('web.numpril', function(require) {
//     "use strict";

//     var core = require('web.core');
//     var widget = require('web.form_widgets');
//     var Widget = require('web.Widget');
//     var FormView = require('web.FormView');
//     var common = require('web.form_common');
//     var Model = require('web.Model');
//     var card_id = 0;
//     var QWeb = core.qweb;
//     var _lt = core._lt;
function recharge(Widget, core,ajax,time,_t, Model){
    var Rechargement = Widget.extend({
       
        start: function () {
            var self = this;
            
            self.$el.html(QWeb.render("display_wecome_recharge"));
            // var hr_employee = new Model('numpril.card');
            // hr_employee.query(['card_balance', 'name'])
            //     .filter([['name', '=', self.barcode]])
            //     .all()
            //     .then(function (res) {
            //         // if (_.isEmpty(res) ) {
            //         //     self.$('.o_hr_attendance_employee').append(_t("Error : Could not find employee linked to user"));
            //         //     return;
            //         // };
            //         console.log(self.barcode)
            //         console.log(res[0])
            //         self.employee = res[0];
            //         //console.log(self.employee)
            //         //self.$el.html(QWeb.render("Consumption_1", {widget: self}));
            //     });

            core.bus.on('barcode_scanned', this, function (barcode) {
                // this.scan(barcode);
                //console.log(barcode)
                self.barcode = barcode;
                card_id = barcode;
                var hr_employee = new Model('numpril.card');
                hr_employee.query(['card_balance', 'name'])
                    .filter([['name', '=', self.barcode]])
                    .all()
                    .then(function (res) {
                        // if (_.isEmpty(res) ) {
                        //     self.$('.o_hr_attendance_employee').append(_t("Error : Could not find employee linked to user"));
                        //     return;
                        // };
                        console.log(res)
                        if(res.length == 0 | res.length > 1){
                            alert('no res')
                        }else{
                        console.log(self.barcode)
                        console.log(res[0]['card_balance'])
                        self.balance = res[0]['card_balance'];
                        //console.log(self.employee)
                        self.$el.html(QWeb.render("rechargement_1", {widget: self}));
                        }
                    });
                


                //self.$el.html(QWeb.render("Consumption_1",{widget: self}));
            });
            return this._super.apply(this, arguments);
        },
        events:{
            "click .deal_recharge_value":"button_click",
        },
        button_click:function(){
            var self = this
            var bb = this.$el.find('.id_for_recharge');
            var confirm = true;
            if(bb[0].value<0){
                alert("消费数字有误！");
                confirm = false;
            }
            console.log(bb[0].value)
            var aa = bb[0].value;
            var model = new Model('numpril.recharge');
            var arg1,arg2;
            // console.log(typeof(aa))
            // console.log(typeof(card_id))
            // console.log(card_id)
            if(confirm){
            model.call("add_recharge",[],{arg1:card_id,arg2:aa})
                .then(function(result){
                    console.log("33")
                    console.log(result)
                    self.balance = result;
                    self.recharge = bb[0].value;
                    self.barcode = card_id;
                    self.$el.html(QWeb.render("rechargement_2", {widget: self}));
                    //self.$el.html(QWeb.render("rechargement_2"),{widget:self});
                    setTimeout(function(){ self.$el.html(QWeb.render("display_wecome_recharge"));},2000);
                    
                });
            }   
        },

    });
    console.log("3")
    core.action_registry.add('numpril_recharge', Rechargement);
    console.log("4")
    return {
        // FieldTestWidget: FieldTestWidget,
        Consumption:Consumption
    };
 
}